﻿/************************************************************************/
/* FileName:        GCBrush
 * Author:          Aric.W
 * Created:         2013/9/17 16:10:34
 * Version:         A001
 * Compiler:        Visual Studio 2010
 * Description:     
 * 
 * History:
 * <Author>         <Time>              <Version>   <Desc>
 * Aric.W    2013/9/17 16:10:34  A001        create
/************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Common
{
    /// <summary>
    /// 画刷
    /// </summary>
    public struct GCBrush
    {
        /// <summary>
        /// 画刷类型
        /// </summary>
        private GCBrushStyle brushStyle;
        public GCBrushStyle BrushStyle
        {
            get { return brushStyle; }
            set { brushStyle = value; }
        }

        /// <summary>
        /// 背景色
        /// </summary>
        private GCColor backgroundColor;

        public GCColor BackgroundColor
        {
            get { return backgroundColor; }
            set { backgroundColor = value; }
        }

        /// <summary>
        /// 前景色，如果是单色画刷，则设置该颜色有效
        /// </summary>
        private GCColor foregroundColor;

        public GCColor ForegroundColor
        {
            get { return foregroundColor; }
            set { foregroundColor = value; }
        }

        /// <summary>
        /// 渐变角度，只用于线型渐近色画刷
        /// </summary>
        private Single angle;
        public Single Angle
        {
            get { return angle; }
            set { angle = value; }
        }

        /// <summary>
        /// 填充矩形
        /// </summary>
        private Rectangle fillRect;

        public Rectangle FillRect
        {
            get { return fillRect; }
            set { fillRect = value; }
        }

        /// <summary>
        /// 放射中心点百分比，只用于路径画刷
        /// </summary>
        private GCPointF centerPoint;

        public GCPointF CenterPoint
        {
            get { return centerPoint; }
            set { centerPoint = value; }
        }

        /// <summary>
        /// 图案填充类型，仅用于图案填充
        /// </summary>
        private GCHatchStyle hatchStyle;

        public GCHatchStyle HatchStyle
        {
            get { return hatchStyle; }
            set { hatchStyle = value; }
        }

        /// <summary>
        /// 焦点所占整个图元的百分比，只用于路径画刷
        /// </summary>
        private GCPointF focusScales;

        public GCPointF FocusScales
        {
            get { return focusScales; }
            set { focusScales = value; }
        }

        /// <summary>
        /// 图片路径，用于纹理画刷
        /// </summary>
        private string imageFileName;

        public string ImageFileName
        {
            get { return imageFileName; }
            set { imageFileName = value; }
        }

        /// <summary>
        /// 循环次数，用于线型及路径渐进色画刷
        /// </summary>
        private int cycleTimes;

        public int CycleTimes
        {
            get { return cycleTimes; }
            set { cycleTimes = value; }
        }

        /// <summary>
        /// 平铺模式，仅用于纹理画刷
        /// </summary>
        private GCWrapMode wrapMode;

        public GCWrapMode WrapMode
        {
            get { return wrapMode; }
            set { wrapMode = value; }
        }

        /// <summary>
        /// 默认画刷类型为SolidBrush
        /// </summary>
        /// <param name="color">画刷颜色</param>
        public GCBrush(GCColor color)
            : this(GCBrushStyle.SolidBrush, color, color, new Rectangle(0, 0, 1, 1))
        {
        }

        /// <summary>
        /// 默认画刷类型为线型渐进画刷
        /// </summary>
        /// <param name="foregroundColor">前景色</param>
        /// <param name="backgroundColor">背景色</param>
        public GCBrush(GCColor foregroundColor, GCColor backgroundColor, Rectangle rect, Single angle)
            : this(GCBrushStyle.LinearGradient, foregroundColor, backgroundColor, rect, angle)
        {
        }

        private GCBrush(GCBrushStyle style, GCColor fgdColor, GCColor bgdColor, Rectangle fillRect, Single angle = 0,
            GCHatchStyle hatchStyle = GCHatchStyle.Cross, string imageFileName = "", int cyleTimes = 1,
            GCWrapMode wrapMode = GCWrapMode.Clamp)
        {
            this.brushStyle = style;
            this.foregroundColor = fgdColor;
            this.backgroundColor = bgdColor;
            this.angle = angle;
            this.fillRect = fillRect;
            this.centerPoint = GCPointF.EmptyPointF;
            this.hatchStyle = hatchStyle;
            this.focusScales = GCPointF.EmptyPointF;
            this.imageFileName = imageFileName;
            this.cycleTimes = cyleTimes;
            this.wrapMode = wrapMode;
        }

        /// <summary>
        /// 获取该结构体数据对应的Brush
        /// </summary>
        /// <returns></returns>
        public Brush GetBrush()
        {
            Brush brush = null;
            switch (this.brushStyle)
            {
                case GCBrushStyle.SolidBrush:
                    brush = new SolidBrush(backgroundColor.GetColor());
                    break;
                case GCBrushStyle.LinearGradient:
                    brush = new LinearGradientBrush(fillRect, foregroundColor.GetColor(), backgroundColor.GetColor(), angle);
                    break;
                case GCBrushStyle.PathGradient:
                    break;
                case GCBrushStyle.HatchBrush:
                    break;
                case GCBrushStyle.TextureBrush:
                    break;
                default:
                    break;
            }
            return brush;
        }

    }//end GCBrush
}
